import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author gao
 * @date 2025/11/3 22:42
 */

public class Solution {

    int aim = 0;
    List<Integer> path;
    List<List<Integer>> ret;

    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        aim = target;
        path = new ArrayList<>();
        ret = new ArrayList<>();

        // 深搜，从索引0开始，当前和为0
        dfs(candidates, 0, 0);
        return ret;
    }

    private void dfs(int[] candidates, int pos, int sum) {
        // 如果当前和等于目标和，将当前路径添加到结果列表中
        if (sum == aim) {
            ret.add(new ArrayList<>(path));
            return;
        }

        // 如果当前和大于目标和或者已经遍历完所有候选数字，则返回
        if (sum > aim || pos >= candidates.length) {
            return;
        }

        for (int i = pos; i < candidates.length; i++) {
            path.add(candidates[i]);
            dfs(candidates, i, sum + candidates[i]);
            // 回溯，移除最后添加的数字
            path.remove(path.size() - 1);
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            int target = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.combinationSum(nums, target));
        }
    }
}